home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Revista CD Expert 31
/
CD Expert nº 31 Jogo Unreal.iso
/
WorldNet
/
Nsstuff
/
NSD3240E
/
NAV40.Z
/
Stack.js
< prev
next >
Wrap
Text File
|
1997-10-22
|
1KB
|
75 lines
/* ==================================================================
FILE: Stack.js
DESCR: Stack object.
NOTES:
================================================================== */
/*
DESCR: Stack class.
PARAMS:
RETURNS:
NOTES:
*/
function stack()
{
this.pointer = -1
this.topItem
this.aItems = new Array
this.push = push
this.pop = pop
this.isEmpty = isEmpty
this.clear = clear
}
/*
DESCR:
PARAMS: item A variable of any type.
RETURNS:
NOTES:
*/
function push( item )
{
this.topItem = item
this.aItems[ ++this.pointer ] = item
}
/*
DESCR:
PARAMS:
RETURNS: The item.
NOTES:
*/
function pop()
{
if ( this.isEmpty() ) return null
this.topItem = this.aItems[ this.pointer - 1 ]
return this.aItems[ this.pointer-- ]
}
/*
DESCR: Empties the stack.
PARAMS:
RETURNS:
NOTES:
*/
function clear()
{
this.pointer = -1
this.topItem = null
}
/*
DESCR:
PARAMS:
RETURNS: true if the stack contains no members; false otherwise.
NOTES:
*/
function isEmpty()
{
return ( this.pointer < 0 ? true : false )
}
// End class definition: stack.